#pragma once

using namespace System;
using namespace NUnit::Framework;
using namespace LatoolNet;

namespace LatoolNetTest {

	[TestFixture]
	public ref class ComplexHermitianBandMatrixTest {
	public:


		[Test]
		void TestFactorizeAndSolve() {
			
			int rownum = 4;
			int colnum = 4;

			ComplexMatrix ^a = gcnew ComplexMatrix(rownum, colnum, MatrixType::ComplexHermitianBand, 1, 1);
			a[0, 0] = Complex(9.39, 0.0);
			a[0, 1] = Complex(1.08, -1.73);

			a[1, 1] = Complex(1.69, 0.0);
			a[1, 2] = Complex(-0.04, 0.29);

			a[2, 2] = Complex(2.65, 0.0);
			a[2, 3] = Complex(-0.33, 2.24);

			a[3, 3] = Complex(2.17, 0.00);

			//Console::WriteLine(a->ToString());

			ComplexMatrix ^ b = gcnew ComplexMatrix(rownum, 1);

			b[0, 0] = Complex(-12.42, 68.42);
			b[1, 0] = Complex(-9.93, 0.88);
			b[2, 0] = Complex(-27.30, -0.01);
			b[3, 0] = Complex(5.31, 23.63);

			//LUFactorization::Factorize(a);
			LinearEquation::Factorize(a);

			//Console::WriteLine(a->ToString());
			//LUFactorization::Solve(a, b);
			LinearEquation::Solve(a, b);
			
			Console::WriteLine(b->ToString());

			Assert::AreEqual(-1.0, b[0, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(8.0, b[0, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(2.0, b[1, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-3.0, b[1, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-4.0, b[2, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-5.0, b[2, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(7.0, b[3, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(6.0, b[3, 0].Imag, 1e-10, "Test: Factorize And Solve.");

		};

		[Test]
		void TestSolve() {
			
			int rownum = 4;
			int colnum = 4;

			ComplexMatrix ^a = gcnew ComplexMatrix(rownum, colnum, MatrixType::ComplexHermitianBand, 1, 1);
			a[0, 0] = Complex(9.39, 0.0);
			a[0, 1] = Complex(1.08, -1.73);

			a[1, 1] = Complex(1.69, 0.0);
			a[1, 2] = Complex(-0.04, 0.29);

			a[2, 2] = Complex(2.65, 0.0);
			a[2, 3] = Complex(-0.33, 2.24);

			a[3, 3] = Complex(2.17, 0.00);

			//Console::WriteLine(a->ToString());

			ComplexMatrix ^ b = gcnew ComplexMatrix(rownum, 1);

			b[0, 0] = Complex(-12.42, 68.42);
			b[1, 0] = Complex(-9.93, 0.88);
			b[2, 0] = Complex(-27.30, -0.01);
			b[3, 0] = Complex(5.31, 23.63);


			//Console::WriteLine(a->ToString());
			//LUFactorization::Solve(a, b);
			LinearEquation::Solve(a, b);

			Console::WriteLine(b->ToString());

			Assert::AreEqual(-1.0, b[0, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(8.0, b[0, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(2.0, b[1, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-3.0, b[1, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-4.0, b[2, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(-5.0, b[2, 0].Imag, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(7.0, b[3, 0].Real, 1e-10, "Test: Factorize And Solve.");
			Assert::AreEqual(6.0, b[3, 0].Imag, 1e-10, "Test: Factorize And Solve.");

		};

	};
}
